package com.ruoyi.project.gxgw_modules.chargeLog.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.gxgw_modules.chargeLog.domain.ChargeLog;
import com.ruoyi.project.gxgw_modules.chargeLog.domain.ReasultByMouth;
import com.ruoyi.project.gxgw_modules.chargeLog.domain.ReasultByYear;
import com.ruoyi.project.gxgw_modules.chargeLog.domain.SumByQuarter;
import com.ruoyi.project.gxgw_modules.chargeLog.service.IChargeLogService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 支付记录 信息操作处理
 * 
 * @author ruoyi
 * @date 2019-01-19
 */
@Controller
@RequestMapping("/gxgw_modules/chargeLog")
public class ChargeLogController extends BaseController
{
    private String prefix = "gxgw_modules/chargeLog";
	
	@Autowired
	private IChargeLogService chargeLogService;
	
	@RequiresPermissions("gxgw_modules:chargeLog:view")
	@GetMapping()
	public String chargeLog()
	{
	    return prefix + "/chargeLog";
	}
	
	/**
	 * 查询支付记录列表
	 */
	@RequiresPermissions("gxgw_modules:chargeLog:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(ChargeLog chargeLog)
	{
		startPage();
		System.out.println(chargeLog.getTime());
        List<ChargeLog> list = chargeLogService.selectChargeLogList(chargeLog);
		return getDataTable(list);
	}
	

	@GetMapping("/selectNumByMouth/{year}/{mouth}")
	@ResponseBody
	public List<ReasultByMouth> selectNumByMouth(@PathVariable("year")String year,@PathVariable("mouth")String mouth){
		return chargeLogService.selectNumByMouth(year, mouth);
	}
	
	@GetMapping("/selectNumByYear/{year}")
	@ResponseBody
	public List<ReasultByYear> selectNumByYear(@PathVariable("year")String year){
		return chargeLogService.selectNumByYear(year);
	}
	
	
	

	/**
	 *按季度统计 
	 */
	@PostMapping("/countByQuart")
	@ResponseBody
	public List<SumByQuarter> countByQuart(String year)
	{
		 List<SumByQuarter> result = chargeLogService.sumByQuart(year);
		return result;
	}
	/**
	 * 导出支付记录列表
	 */
	@RequiresPermissions("gxgw_modules:chargeLog:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ChargeLog chargeLog)
    {
    	List<ChargeLog> list = chargeLogService.selectChargeLogList(chargeLog);
        ExcelUtil<ChargeLog> util = new ExcelUtil<ChargeLog>(ChargeLog.class);
        return util.exportExcel(list, "chargeLog");
    }
	
	/**
	 * 新增支付记录
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存支付记录
	 */
	@RequiresPermissions("gxgw_modules:chargeLog:add")
	@Log(title = "支付记录", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(ChargeLog chargeLog)
	{		
		return toAjax(chargeLogService.insertChargeLog(chargeLog));
	}

	/**
	 * 修改支付记录
	 */
	@GetMapping("/edit/{chargeLogId}")
	public String edit(@PathVariable("chargeLogId") Integer chargeLogId, ModelMap mmap)
	{
		ChargeLog chargeLog = chargeLogService.selectChargeLogById(chargeLogId);
		mmap.put("chargeLog", chargeLog);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存支付记录
	 */
	@RequiresPermissions("gxgw_modules:chargeLog:edit")
	@Log(title = "支付记录", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(ChargeLog chargeLog)
	{		
		return toAjax(chargeLogService.updateChargeLog(chargeLog));
	}
	
	/**
	 * 删除支付记录
	 */
	@RequiresPermissions("gxgw_modules:chargeLog:remove")
	@Log(title = "支付记录", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(chargeLogService.deleteChargeLogByIds(ids));
	}
	
}
